<?php
/**
 * 账户明细查询
 * @author Administrator
 *
 */
class accountDetail extends CControllerMerchantBase{
	
	public function show()
	{
		$this->_title="账户明细查询";
		
		$icModel = new integralChangeModel();
		
		$s_time=$this->getRequestData("txt_s_time","get",date("Y-m"."-01"));
		$e_time=$this->getRequestData("txt_e_time","get",date("Y-m-d"));
		$supplier_id=$this->getRequestData("sel_supplier","get","-1");
		$owner_card=$this->getRequestData("txt_card_value","get","");
		$owner_name=$this->getRequestData("txt_name_value","get","");
		$cost_type=$this->getRequestData("sel_cost_type","get","-1");
		
		$e_time_old = $e_time;
		$e_time = date("Y-m-d",strtotime($e_time." +1 day"));

		$where = "c.owner_id=o.owner_id and shop_id=".$this->_shopID;
		$where .= " and cost_time>to_date('".$s_time."','yyyy-mm-dd hh24:mi:ss')";
		$where .= " and cost_time<=to_date('".$e_time."','yyyy-mm-dd hh24:mi:ss')";
		
		$urlParam["txt_s_time"] = $s_time;
		$urlParam["txt_e_time"] = $e_time_old;
		
		if($supplier_id>0)
		{
			$where .= " and s_id=".$supplier_id;
			$urlParam["sel_supplier"] = $supplier_id;
		}

		if($owner_card)
		{
			$where .= " and owner_card='".$owner_card."'";
			$urlParam["txt_card_value"] = $owner_card;
		}
		if($owner_name)
		{
			$where .= " and owner_name='".$owner_name."'";
			$urlParam["txt_name_value"] = $owner_name;
		}
		
		if($cost_type>0)
		{
			$where .= " and cost_type=".$cost_type;
			$urlParam["sel_cost_type"] = $cost_type;
		}
		
		$pageIndex = $this->getRequestData("page","GET",1);
		$pageSize = 10;
		$c = 0;
		
		$pageUrl = $this->getUrlParam($urlParam, array("txt_card_value","txt_name_value"));
		$pageUrl = $pageUrl? "?".$pageUrl:"";
		
		$list = $icModel->selectPage($pageIndex,$pageSize,
			"c_id,s_id,pay_id,cost_money,cost_type,cost_time,owner_card,cost_shop_before_money,cost_shop_after_money,cost_money_t,owner_name,cancel_pay_id",
		$where,"c_id desc","",$c,"t_integral_change c, t_owner o");
		$pageStr = CPage::showPage($pageIndex,$pageSize,$c,$pageUrl);
		
		$supplierModel = new supplierModel(); 
		$sInfo = $supplierModel->selectDataSetByWhere("","s_name,s_id",array(),"del_flag=0 and shop_id=".$this->_shopID);
		
		foreach($list as &$item)
		{
			//$payID = $item["pay_id"];
			//$payID = substr($payID,0,8)." ".substr($payID,8);
			//$item["pay_id"] = $payID;
			
			foreach($sInfo as $sitem)
			{
				if($item["s_id"] == $sitem["s_id"])
				{
					$item["s_name"] = $sitem["s_name"];
				}
			}
		}

		$this->setViewParam("sInfo", $sInfo);
		
		$this->setJsFile(array("/My97DatePicker/WdatePicker.js"));
		$this->render("account_detail",array("list"=>$list,"s_time"=>$s_time,
			"e_time"=>$e_time_old,"s_id"=>$supplier_id,"owner_card"=>$owner_card,
			"owner_name"=>$owner_name,"cost_type"=>$cost_type,"pageStr"=>$pageStr
		));
	}
}